package com.shen.xiang.test.mybatis;

import com.shen.xiang.test.pojo.Person;
import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.core.ResolvableType;

/**
 * 实现了BeanDefinitionRegistryPostProcessor接口 在beanfactory工厂初始化完成之后
 * 会增强beanfactory
 *
 * beanfatory会获取所有的beandefinition对象 从中判断有哪些实现了bfpp接口的类 之后生成这个对象后执行
 * bfpp接口的方法来对这个工厂进行增强
 */
@Data
public class MyBatisScanConfig implements BeanDefinitionRegistryPostProcessor {

    private String basePackages;

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        //创建mybatis扫描类
        ClassPathConfig classPathConfig = new ClassPathConfig(registry);
        //注册过滤器 过滤一些不是mapper接口的对象
        classPathConfig.registerFilters();
        //开始扫描
        classPathConfig.doScan(basePackages);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}